package com.jlpay.openapi.demo.ledger.balancesplit;

import com.jlpay.open.jlpay.sdk.java.model.ledger.request.BalanceSplitRequest;
import com.jlpay.open.jlpay.sdk.java.model.ledger.response.BalanceSplitResponse;
import com.jlpay.open.jlpay.sdk.java.utils.json.JsonUtils;
import com.jlpay.openapi.demo.JlpayOpenApiService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Arrays;

/**
 *
 * @author dengwenning
 * @since 2024/8/30
 **/
public class BalanceSplitService {

    private static final Logger LOGGER = LoggerFactory.getLogger(BalanceSplitService.class);

    public static void main(String[] args) {
        BalanceSplitRequest balanceSplitRequest = buildBalanceSplitRequest();
        BalanceSplitResponse balanceSplitResponse = JlpayOpenApiService.openMerchService()
                .post(balanceSplitRequest, BalanceSplitResponse.class);
        LOGGER.info("余额分账请求响应:{}", JsonUtils.toString(balanceSplitResponse));
    }

    private static BalanceSplitRequest buildBalanceSplitRequest() {
        BalanceSplitRequest balanceSplitRequest = new BalanceSplitRequest();
        balanceSplitRequest.setOrgCode("50720711");
        balanceSplitRequest.setMchId("849581183510017");
        balanceSplitRequest.setOutOrderNo("045e1314f7784f46bf9d590dc65c7");
        balanceSplitRequest.setTotalAmount(2000);
        BalanceSplitRequest.Receiver receiver1 = new BalanceSplitRequest.Receiver();
        receiver1.setRevMchId("849584307420004");
        receiver1.setAmount(500);
        receiver1.setDescription("分账账户1");
        BalanceSplitRequest.Receiver receiver2 = new BalanceSplitRequest.Receiver();
        receiver2.setRevMchId("849602058120001");
        receiver2.setAmount(1500);
        receiver2.setDescription("分账账户2");
        balanceSplitRequest.setReceivers(Arrays.asList(receiver1,receiver2));
        return balanceSplitRequest;
    }
}
